﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using ZLCMS.Business.ShopCart;
using ZLCMS.Business.Util;
using ZLCMS.Business.Ajax;

namespace ZLCMS.Web.AJAXServer.ShopCart
{
    /// <summary>
    /// 购物车相关的服务
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class ShopCartServer : System.Web.Services.WebService
    {
        /// <summary>
        /// 增加购物车内指定产品的数量
        /// </summary>
        /// <param name="productNo"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        [WebMethod]
        public string AddProductQuantity(string productNo, int num)
        {
            try
            {
                new ShoppingCartKit().AddProductQuantity(productNo, num);
            }
            catch (System.Exception ex)
            {
                return AjaxReturnInfo.Failed;
            }
            return AjaxReturnInfo.Success;
        }

        /// <summary>
        /// 更新购物车内指定产品的数量
        /// </summary>
        /// <param name="productNo"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        [WebMethod]
        public string UpdateProductQuantity(string productNo, int num)
        {
            try
            {
                new ShoppingCartKit().UpdateProductQuantity(productNo, num);
            }
            catch (System.Exception ex)
            {
                return AjaxReturnInfo.Failed;
            }

            return AjaxReturnInfo.Success;
        }

        /// <summary>
        /// 删除购物车中的产品
        /// </summary>
        /// <param name="productNo"></param>
        /// <returns></returns>
        [WebMethod]
        public string RemoveProduct(string productNo)
        {
            try
            {
                new ShoppingCartKit().RemoveProduct(productNo);
            }
            catch (System.Exception ex)
            {
                return AjaxReturnInfo.Failed;
            }

            return AjaxReturnInfo.Success;
        }

        /// <summary>
        /// 增加产品
        /// </summary>
        /// <param name="productNo"></param>
        /// <param name="num"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        [WebMethod]
        public string AddProduct(string productNo, int num, string items)
        {
            try
            {
                new ShoppingCartKit().AddProduct(new ShopCartCookiesInfo() { ProductNo = productNo, Quantity = num, Items = items });
            }
            catch (System.Exception ex)
            {
                return AjaxReturnInfo.Failed;
            }
            return AjaxReturnInfo.Success;
        }
    }
}
